<?php
include('../../__global.php');
class aj_getLatestComment extends ml_controller 
{
    private $_rid;
    private $_uid;
    
    public function initParam()
    {
        $this->_rid=$this->input('rid','g');
        $this->_uid=ml_tool_resid::resid2uid($this->_rid);
    }
    public function checkParam()
    {
        $this->check_referer();
        if(!ml_tool_resid::is_resid($this->_rid))
            $this->api_output(ML_RCODE_PARAM);

        if(ml_tool_resid::resid2type($this->_rid) != ML_CONTENT_XRANK_GOODS ){
            $this->api_output(ML_RCODE_PARAM);
        }
    }
    
    public function main()
    {
        $oComment=new ml_model_dbComment();
        $oComment->getCountsByRid($this->_rid);
        $totalNum=$oComment->get_data();
        
        if($totalNum['num'] == 0){
            $this->api_output(ML_RCODE_SUCC,'empty');
        }
        
        $rs=$oComment->getLatestCommentByRid($this->_rid);
        if(!$rs) 
            $this->api_output(ML_RCODE_BUSY);
        $newComment=$oComment->get_data();
        $newComment=ml_tool_commentOutput::formatComment($newComment);
        $this->api_output(ML_RCODE_SUCC,$newComment[0]);
    }
    
}
new aj_getLatestComment();